<template>
  <div class="chart-container app-container nohead">
    <div style="float: right;padding-right: 10px; margin-top:20px;">
      <el-button type="primary" icon="icon-ym icon-ym-extend-bar-chart" @click="change('plain')">柱状
      </el-button>
      <el-button type="warning" icon="icon-ym icon-ym-extend-mail-forward" @click="change('inverted')">条形</el-button>
    </div>
    <highcharts :options="chartOptions" :callback="myCallback" style="height:530px;margin-top:30px;"></highcharts>
  </div>
</template>

<script>

import { Chart } from "highcharts-vue";
import request from '@/utils/request'
export default {

  name: 'extend-graphDemo-highchartsColumn',
  components: {
    highcharts: Chart
  },
  data() {
    return {
      dataObj: {
        receivefees: [],
        officefees: [],
        meetingfees: [],
        busfees: [],
        remainingAmount: 0

      },
      chartOptions: {}

    }
  },
 async mounted() {
    this.initData()



   },

  methods: {
    initData() {
      request({
        url: `/api/example/Bususefee/getHighchartData`,
        method: 'post'
      }).then(res => {
        console.log('-----', res);
        // receivefees = res.data.receivefees;
        // officefees = res.data.officefees;
        // meetingfees = res.data.meetingfees;
        // busfees = res.data.busfees;
        this.dataObj = res.data
        this.chartOptions = {
        chart: {
          type: 'column'
        },
        title: {
          text: '燃机四费个月使用情况表 (总费剩余'+this.dataObj.remainingAmount+'元)'
        },
        subtitle: {
          text: ''
        },
        xAxis: {
          categories: [
            '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'
          ],
          crosshair: true
        },
        yAxis: {
          min: 0,
          title: {
            text: '四费花销 (元)'
          }
        },
        tooltip: {
          // head + 每个 point + footer 拼接成完整的 table
          headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
          pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
            '<td style="padding:0"><b>{point.y:.1f} 元</b></td></tr>',
          footerFormat: '</table>',
          shared: true,
          useHTML: true
        },
        plotOptions: {
          column: {
            borderWidth: 0
          }
        },
        credits: {
          enabled: false
        },
        series: [{
          name: '接待费',
          data: this.dataObj.receivefees
        }, {
          name: '办公费',
          data: this.dataObj.officefees
        }, {
          name: '会议费',
          data: this.dataObj.meetingfees
        }, {
          name: '公车费',
          data: this.dataObj.busfees
        }]
      }
      })
    },

    myCallback() {
      console.log("this is callback function");
    },
    change(key) {
      switch (key) {
        case 'plain':
          this.chartOptions.chart = {
            inverted: false,
          }
          this.chartOptions.subtitle = {
            text: '柱状'
          }
          break;
        case 'inverted':
          this.chartOptions.chart = {
            inverted: true,
          }
          this.chartOptions.subtitle = {
            text: '条形'
          }

          break;
      }
    },
  }
}
</script>
